// 蜂窝蜜造平台生成代码，如手工更改，请添加到 .beeignore 忽略生成
package com.fowo.api.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fowo.api.common.model.IdListPo;
import com.fowo.api.common.model.IdPo;
import com.fowo.api.common.model.ImportRow;
import com.fowo.api.common.model.OptionItem;
import com.fowo.api.common.model.R;
import com.fowo.api.common.util.ResponseUtils;
import com.fowo.api.entity.Requisition;
import com.fowo.api.model.requisition.RequisitionImportPo;
import com.fowo.api.model.requisition.RequisitionItemVo;
import com.fowo.api.model.requisition.RequisitionSearchParamPo;
import com.fowo.api.model.requisition.RequisitionVo;
import com.fowo.api.service.RequisitionService;
import com.fowo.api.sys.entity.SysFile;
import com.fowo.api.user.model.JwtUserInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.core.io.ClassPathResource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.StreamUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Tag(name = "调拨单")
@RequestMapping("/api/requisition")
@RestController
public class RequisitionController {

  @Resource
  private RequisitionService service;

  @Operation(summary = "查询结果")
  @GetMapping
  public R<List<RequisitionItemVo>> search(RequisitionSearchParamPo search) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.search(search));
  }

  @Operation(summary = "快速查询选项(有缓存)")
  @GetMapping("options")
  public R<List<OptionItem<RequisitionItemVo>>> searchOptions(
    RequisitionSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.searchOptions(search));
  }

  @Operation(summary = "查询最后更新时间")
  @GetMapping("lastUpdateTime")
  public R<Date> searchLastUpdateTime(RequisitionSearchParamPo search) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.searchLastUpdateTime(search));
  }

  @Operation(summary = "获取分页查询结果")
  @GetMapping("page")
  public R<Page<RequisitionItemVo>> getPage(RequisitionSearchParamPo search) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.pageSearch(search));
  }

  @Operation(summary = "获取包括子表的查询结果")
  @GetMapping("page-with-child")
  public R<Page<?>> getPageWithChild(RequisitionSearchParamPo search) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.pageWithChildSearch(search));
  }

  @Operation(summary = "仅获取子表的查询结果")
  @GetMapping("page-only-child/{parentId}")
  public R<Page<?>> getPageOnlyChild(
    @PathVariable Long parentId,
    RequisitionSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.pageOnlyChildSearch(parentId, search));
  }

  @Operation(summary = "查询是否后台下载")
  @GetMapping("getBackgroundExportFlag")
  public R<Boolean> getBackgroundExportFlag(RequisitionSearchParamPo search) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.getBackgroundExportFlag(search));
  }

  @Operation(summary = "获取详情")
  @GetMapping("{id}")
  public R<RequisitionVo> getVoById(@PathVariable Long id) {
    return R.data(() -> service.getVoById(id));
  }

  @Operation(summary = "获取调拨单号相关的编号列表")
  @GetMapping("rqt-sn/{texts}/ids")
  public R<List<Long>> getIdsByRqtSn(@PathVariable String texts) {
    List<String> nameList = Arrays
      .stream(texts.split(","))
      .collect(Collectors.toList());
    return R.data(() -> service.getIdsByRqtSn(nameList));
  }

  @Operation(summary = "获取编号相关的调拨单号列表")
  @GetMapping("rqt-sn/{ids}")
  public R<List<String>> getVoById(@PathVariable String ids) {
    List<Long> idList = Arrays
      .asList(ids.split(","))
      .stream()
      .map(Long::valueOf)
      .collect(Collectors.toList());
    return R.data(() -> service.getRqtSnByIds(idList));
  }

  @PreAuthorize("@am.canAccess('requisitionCreate')")
  @Operation(summary = "新增")
  @PostMapping
  public R<Long> create(@Validated @RequestBody RequisitionVo model) {
    return R.data(() -> service.create(model));
  }

  @PreAuthorize("@am.canAccess('requisitionEdit')")
  @Operation(summary = "更新")
  @PutMapping
  public R update(@RequestBody RequisitionVo model) {
    return R.run(() -> service.update(model));
  }

  @PreAuthorize("@am.canAccess('requisitionEdit')")
  @Operation(summary = "编辑更新")
  @PutMapping("edit")
  public R updateForEdit(@RequestBody RequisitionVo model) {
    return R.run(() -> service.updateForEdit(model));
  }

  @PreAuthorize("@am.canAccess('requisitionDelete')")
  @Operation(summary = "删除")
  @DeleteMapping("{id}")
  public R delete(@PathVariable Long id) {
    return R.run(() -> service.delete(id));
  }

  @PreAuthorize("@am.canAccess('requisitionDelete')")
  @Operation(summary = "批量删除")
  @DeleteMapping("batch")
  public R batchDelete(@RequestBody IdListPo po) {
    return R.run(() -> service.batchDelete(po.getIds()));
  }

  @PreAuthorize("@am.canAccess('requisitionImport')")
  @Operation(summary = "导入预览")
  @PostMapping("import-preview")
  public R<List<ImportRow<RequisitionImportPo>>> importPreview(
    @RequestBody SysFile sysFile,
    @RequestParam(name = "template", required = false) Long templateId,
    @RequestParam(
      name = "allowOverrides",
      defaultValue = "false"
    ) boolean allowOverrides
  ) {
    return R.data(() ->
      service.importPreview(sysFile, templateId, allowOverrides)
    );
  }

  @PreAuthorize("@am.canAccess('requisitionImport')")
  @Operation(summary = "完成导入")
  @PostMapping("import-done")
  public R importDone(
    @RequestBody List<ImportRow<RequisitionImportPo>> rows,
    @RequestParam(name = "template", required = false) Long templateId
  ) {
    return R.run(() -> service.importDone(rows, templateId));
  }

  @Operation(summary = "下载导入模版")
  @GetMapping("import/template")
  public void downloadImportTemplate(HttpServletResponse response)
    throws IOException {
    ResponseUtils.setAttachmentFileName(response, "调拨单导入模版.xlsx");
    InputStream inputStream = new ClassPathResource(
      "templates/Requisition.xlsx"
    )
      .getInputStream();
    StreamUtils.copy(inputStream, response.getOutputStream());
  }

  @Operation(summary = "导出")
  @GetMapping("export")
  @PreAuthorize("@am.canAccess('requisitionExport')")
  public void export(
    @RequestParam(name = "template", required = false) Long templateId,
    RequisitionSearchParamPo search,
    HttpServletResponse response
  ) throws Exception {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    service.export(templateId, search, response);
  }

  @PreAuthorize("@am.canAccess('requisitionRevocationOrder')")
  @Operation(summary = "撤销")
  @PostMapping("revocationOrder")
  public R revocationOrder(@RequestBody IdPo po) {
    return R.run(() -> service.revocationOrder(po.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionLockBadOut')")
  @Operation(summary = "次品锁定出库")
  @PostMapping("lockBadOut")
  public R lockBadOut(@RequestBody IdPo idPo) {
    return R.run(() -> service.lockBadOut(idPo.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionLockGoodOut')")
  @Operation(summary = "良品锁定出库")
  @PostMapping("lockGoodOut")
  public R lockGoodOut(@RequestBody IdPo idPo) {
    return R.run(() -> service.lockGoodOut(idPo.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionRevocationBadOut')")
  @Operation(summary = "次品出库撤销")
  @PostMapping("revocationBadOut")
  public R revocationBadOut(@RequestBody IdPo idPo) {
    return R.run(() -> service.revocationBadOut(idPo.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionRevocationGoodOut')")
  @Operation(summary = "良品出库撤销")
  @PostMapping("revocationGoodOut")
  public R revocationGoodOut(@RequestBody IdPo idPo) {
    return R.run(() -> service.revocationGoodOut(idPo.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionRevocationBadIn')")
  @Operation(summary = "次品入库撤销")
  @PostMapping("revocationBadIn")
  public R revocationBadIn(@RequestBody IdPo idPo) {
    return R.run(() -> service.revocationBadIn(idPo.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionRevocationGoodIn')")
  @Operation(summary = "良品入库撤销")
  @PostMapping("revocationGoodIn")
  public R revocationGoodIn(@RequestBody IdPo idPo) {
    return R.run(() -> service.revocationGoodIn(idPo.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionBadOut')")
  @Operation(summary = "次品出库")
  @PostMapping("badOut")
  public R badOut(@RequestBody IdPo idPo) {
    return R.run(() -> service.badOut(idPo.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionGoodOut')")
  @Operation(summary = "良品出库")
  @PostMapping("goodOut")
  public R goodOut(@RequestBody IdPo idPo) {
    return R.run(() -> service.goodOut(idPo.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionBadIn')")
  @Operation(summary = "次品入库")
  @PostMapping("badIn")
  public R badIn(@RequestBody IdPo idPo) {
    return R.run(() -> service.badIn(idPo.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionGoodIn')")
  @Operation(summary = "良品入库")
  @PostMapping("goodIn")
  public R goodIn(@RequestBody IdPo idPo) {
    return R.run(() -> service.goodIn(idPo.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionLockGoodIinventory')")
  @Operation(summary = "锁良品库存")
  @PostMapping("lockGoodIinventory")
  public R lockGoodIinventory(@RequestBody IdPo idPo) {
    return R.run(() -> service.lockGoodIinventory(idPo.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionLockGoodIinventoryBin')")
  @Operation(summary = "锁仓位良品库存")
  @PostMapping("lockGoodIinventoryBin")
  public R lockGoodIinventoryBin(@RequestBody IdPo idPo) {
    return R.run(() -> service.lockGoodIinventoryBin(idPo.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionLockBadIinventory')")
  @Operation(summary = "锁次品库存")
  @PostMapping("lockBadIinventory")
  public R lockBadIinventory(@RequestBody IdPo idPo) {
    return R.run(() -> service.lockBadIinventory(idPo.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionLockBadIinventoryBin')")
  @Operation(summary = "锁仓位次品库存")
  @PostMapping("lockBadIinventoryBin")
  public R lockBadIinventoryBin(@RequestBody IdPo idPo) {
    return R.run(() -> service.lockBadIinventoryBin(idPo.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionReleaseGoodInventory')")
  @Operation(summary = "释放良品库存")
  @PostMapping("releaseGoodInventory")
  public R releaseGoodInventory(@RequestBody IdPo idPo) {
    return R.run(() -> service.releaseGoodInventory(idPo.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionReleaseGoodInventoryBin')")
  @Operation(summary = "释放良品库存仓位")
  @PostMapping("releaseGoodInventoryBin")
  public R releaseGoodInventoryBin(@RequestBody IdPo idPo) {
    return R.run(() -> service.releaseGoodInventoryBin(idPo.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionReleaseBadInventory')")
  @Operation(summary = "释放次品库存")
  @PostMapping("releaseBadInventory")
  public R releaseBadInventory(@RequestBody IdPo idPo) {
    return R.run(() -> service.releaseBadInventory(idPo.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionReleaseBadInventoryBin')")
  @Operation(summary = "释放次品库存仓位")
  @PostMapping("releaseBadInventoryBin")
  public R releaseBadInventoryBin(@RequestBody IdPo idPo) {
    return R.run(() -> service.releaseBadInventoryBin(idPo.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionRefer')")
  @Operation(summary = "提交")
  @PostMapping("refer")
  public R refer(@RequestBody IdPo po) {
    return R.run(() -> service.refer(po.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionSubmitTransfer')")
  @Operation(summary = "提交并调拨")
  @PostMapping("submitTransfer")
  public R submitTransfer(@RequestBody IdPo po) {
    return R.run(() -> service.submitTransfer(po.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionConfirmationTransfer')")
  @Operation(summary = "确认调拨")
  @PostMapping("confirmationTransfer")
  public R confirmationTransfer(@RequestBody IdPo po) {
    return R.run(() -> service.confirmationTransfer(po.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionConfirmReceipt')")
  @Operation(summary = "确认收货")
  @PostMapping("confirmReceipt")
  public R confirmReceipt(@RequestBody IdPo po) {
    return R.run(() -> service.confirmReceipt(po.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionTjcommit')")
  @Operation(summary = "提交")
  @PostMapping("tjcommit")
  public R tjcommit(@RequestBody IdListPo po) {
    return R.run(() -> service.tjcommit(po.getIds()));
  }

  @PreAuthorize("@am.canAccess('requisitionNotarize')")
  @Operation(summary = "确认调拨")
  @PostMapping("notarize")
  public R notarize(@RequestBody IdListPo po) {
    return R.run(() -> service.notarize(po.getIds()));
  }

  @PreAuthorize("@am.canAccess('requisitionCommitAndRqt')")
  @Operation(summary = "提交并调拨")
  @PostMapping("commitAndRqt")
  public R commitAndRqt(@RequestBody IdListPo po) {
    return R.run(() -> service.commitAndRqt(po.getIds()));
  }

  @PreAuthorize("@am.canAccess('requisitionAllAOG')")
  @Operation(summary = "全部到货")
  @PostMapping("allAOG")
  public R allAOG(@RequestBody IdListPo po) {
    return R.run(() -> service.allAOG(po.getIds()));
  }

  @PreAuthorize("@am.canAccess('requisitionReleaseinventory')")
  @Operation(summary = "释放库存")
  @PostMapping("releaseinventory")
  public R releaseinventory(@RequestBody IdListPo po) {
    return R.run(() -> service.releaseinventory(po.getIds()));
  }

  @PreAuthorize("@am.canAccess('requisitionPresent')")
  @Operation(summary = "提交")
  @PostMapping("present")
  public R present(@RequestBody IdPo po) {
    return R.run(() -> service.present(po.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionSubmitAndTransfer')")
  @Operation(summary = "提交并调拨")
  @PostMapping("submitAndTransfer")
  public R submitAndTransfer(@RequestBody IdPo po) {
    return R.run(() -> service.submitAndTransfer(po.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionConfirmationTransfers')")
  @Operation(summary = "确认调拨")
  @PostMapping("confirmationTransfers")
  public R confirmationTransfers(@RequestBody IdPo po) {
    return R.run(() -> service.confirmationTransfers(po.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionConfirmReceipts')")
  @Operation(summary = "确认收货")
  @PostMapping("confirmReceipts")
  public R confirmReceipts(@RequestBody IdPo po) {
    return R.run(() -> service.confirmReceipts(po.getId()));
  }

  @PreAuthorize("@am.canAccess('requisitionRevocation')")
  @Operation(summary = "撤销")
  @PostMapping("revocation")
  public R revocation(@RequestBody IdPo po) {
    return R.run(() -> service.revocation(po.getId()));
  }

  /**
   * 视图选项卡标题上显示计数
   */
  @Operation(summary = "视图选项卡标题上显示计数")
  @GetMapping("getTabHeaderShowTotal")
  public R<Map> getTabHeaderShowTotal() {
    return R.data(() -> service.getTabHeaderShowTotal());
  }

  @Operation(summary = "全部")
  @GetMapping("all-rqt")
  public R<List<RequisitionItemVo>> allRqt(RequisitionSearchParamPo search) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.allRqt(search));
  }

  @Operation(summary = "全部分页")
  @GetMapping("all-rqtPage")
  public R<Page<RequisitionItemVo>> allRqtPage(
    RequisitionSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.allRqtPage(search));
  }

  @Operation(summary = "全部包括子表的查询结果")
  @GetMapping("all-rqtPage-with-child")
  public R<Page<?>> allRqtPageWithChild(RequisitionSearchParamPo search) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.allRqtPageWithChildSearch(search));
  }

  @Operation(summary = "全部最后更新时间")
  @GetMapping("all-rqtLastUpdateTime")
  public R<Date> allRqtLastUpdateTime(RequisitionSearchParamPo search) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.allRqtLastUpdateTime(search));
  }

  @Operation(summary = "待配货")
  @GetMapping("goodstobeallocated")
  public R<List<RequisitionItemVo>> goodstobeallocated(
    RequisitionSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.goodstobeallocated(search));
  }

  @Operation(summary = "待配货分页")
  @GetMapping("goodstobeallocatedPage")
  public R<Page<RequisitionItemVo>> goodstobeallocatedPage(
    RequisitionSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.goodstobeallocatedPage(search));
  }

  @Operation(summary = "待配货包括子表的查询结果")
  @GetMapping("goodstobeallocatedPage-with-child")
  public R<Page<?>> goodstobeallocatedPageWithChild(
    RequisitionSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.goodstobeallocatedPageWithChildSearch(search));
  }

  @Operation(summary = "待配货最后更新时间")
  @GetMapping("goodstobeallocatedLastUpdateTime")
  public R<Date> goodstobeallocatedLastUpdateTime(
    RequisitionSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.goodstobeallocatedLastUpdateTime(search));
  }

  @Operation(summary = "待调拨")
  @GetMapping("tobetransferred")
  public R<List<RequisitionItemVo>> tobetransferred(
    RequisitionSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.tobetransferred(search));
  }

  @Operation(summary = "待调拨分页")
  @GetMapping("tobetransferredPage")
  public R<Page<RequisitionItemVo>> tobetransferredPage(
    RequisitionSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.tobetransferredPage(search));
  }

  @Operation(summary = "待调拨包括子表的查询结果")
  @GetMapping("tobetransferredPage-with-child")
  public R<Page<?>> tobetransferredPageWithChild(
    RequisitionSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.tobetransferredPageWithChildSearch(search));
  }

  @Operation(summary = "待调拨最后更新时间")
  @GetMapping("tobetransferredLastUpdateTime")
  public R<Date> tobetransferredLastUpdateTime(
    RequisitionSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.tobetransferredLastUpdateTime(search));
  }

  @Operation(summary = "待收货")
  @GetMapping("waitforreceiving")
  public R<List<RequisitionItemVo>> waitforreceiving(
    RequisitionSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.waitforreceiving(search));
  }

  @Operation(summary = "待收货分页")
  @GetMapping("waitforreceivingPage")
  public R<Page<RequisitionItemVo>> waitforreceivingPage(
    RequisitionSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.waitforreceivingPage(search));
  }

  @Operation(summary = "待收货包括子表的查询结果")
  @GetMapping("waitforreceivingPage-with-child")
  public R<Page<?>> waitforreceivingPageWithChild(
    RequisitionSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.waitforreceivingPageWithChildSearch(search));
  }

  @Operation(summary = "待收货最后更新时间")
  @GetMapping("waitforreceivingLastUpdateTime")
  public R<Date> waitforreceivingLastUpdateTime(
    RequisitionSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.waitforreceivingLastUpdateTime(search));
  }

  @Operation(summary = "已完成")
  @GetMapping("completed")
  public R<List<RequisitionItemVo>> completed(RequisitionSearchParamPo search) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.completed(search));
  }

  @Operation(summary = "已完成分页")
  @GetMapping("completedPage")
  public R<Page<RequisitionItemVo>> completedPage(
    RequisitionSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.completedPage(search));
  }

  @Operation(summary = "已完成包括子表的查询结果")
  @GetMapping("completedPage-with-child")
  public R<Page<?>> completedPageWithChild(RequisitionSearchParamPo search) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.completedPageWithChildSearch(search));
  }

  @Operation(summary = "已完成最后更新时间")
  @GetMapping("completedLastUpdateTime")
  public R<Date> completedLastUpdateTime(RequisitionSearchParamPo search) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.completedLastUpdateTime(search));
  }

  @Operation(summary = "已撤销")
  @GetMapping("undone")
  public R<List<RequisitionItemVo>> undone(RequisitionSearchParamPo search) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.undone(search));
  }

  @Operation(summary = "已撤销分页")
  @GetMapping("undonePage")
  public R<Page<RequisitionItemVo>> undonePage(
    RequisitionSearchParamPo search
  ) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.undonePage(search));
  }

  @Operation(summary = "已撤销包括子表的查询结果")
  @GetMapping("undonePage-with-child")
  public R<Page<?>> undonePageWithChild(RequisitionSearchParamPo search) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(service.undonePageWithChildSearch(search));
  }

  @Operation(summary = "已撤销最后更新时间")
  @GetMapping("undoneLastUpdateTime")
  public R<Date> undoneLastUpdateTime(RequisitionSearchParamPo search) {
    JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
    if (jwtUserInfo != null) {
      search.setCurrentUserId(jwtUserInfo.getUserId());
    }
    return R.data(() -> service.undoneLastUpdateTime(search));
  }
}
